<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>数据字典操作</title>
    <script src="../../../../res/js/jquery-3.4.1.min.js"></script>
    <script src="../../../../res/layui/layui.js" charset="utf-8"></script>
    <script src="../../../../res/js/Tools.js"></script>
    <link rel="stylesheet" href="../../../../res/layui/css/layui.css" media="all">
    <link href="../../../../res/echarts/eleTree.css" rel="stylesheet"/>
    <script src="../../../../res/echarts/eleTree.js"></script>
    <link rel="shortcut icon" type="image/x-icon" href="../../../../res/images/favicon.ico">
    <script src="../../../../res/js/login_common.js" charset="utf-8"></script>
    <style type="text/css">
        body {
            padding: 10px;
        }
    </style>
</head>
<body>
<form class="layui-form layui-form-pane" action="">
    <input type="hidden" id="pkDataDictionaryId" name="pkDataDictionaryId">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">字典名称</label>
            <div class="layui-input-inline">
                <input type="text" name="dataDictionaryName" id="dataDictionaryName" lay-verify="required" placeholder="请输入所属模块（必填）"
                       autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">关键字</label>
            <div class="layui-input-inline">
                <input type="text" name="dataDictionaryKeyword" id="dataDictionaryKeyword" lay-verify="required" placeholder="请输入所属模块（必填）"
                       autocomplete="off"
                       class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">说明</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入内容" id="remake" name="remake" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn site-demo-active" lay-submit="" lay-filter="demo1" id="sub">立即提交</button>
        </div>
    </div>
</form>
<script>
    var houses;
    layui.use(['form', 'layedit', 'laydate', 'layer'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;

        const pkDataDictionaryId = getQueryString("pkDataDictionaryId");
        const show=getQueryString("show");
        //监听提交
        form.on('submit(demo1)', function (data) {
            // 单击之后提交按钮不可选,防止重复提交
            var DISABLED = 'layui-btn-disabled';
            // 增加样式
            $('.site-demo-active').addClass(DISABLED);
            // 增加属性
            $('.site-demo-active').attr('disabled', 'disabled');
            let res=postAjax(getRootPath()+"OaDataDictionaryAction/addOrUpdate",data.field);
            if(res.code===1){
                parent.layui.table.reload('test');//刷新父页面
                layer.msg("操作成功", {icon: 1});
                const index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                parent.layer.close(index);
            }else{
                layer.msg("操作失败");
            }
            return false;
        });

        //表单取值
        layui.$('#LAY-component-form-getval').on('click', function () {
            var data = form.val('example');
            alert(JSON.stringify(data));
        });

        if(pkDataDictionaryId){
            $("#pkDataDictionaryId").val(pkDataDictionaryId);
            let res=getAjaxById(getRootPath()+'OaDataDictionaryAction/findById/'+pkDataDictionaryId);
            if(res){
                $("#dataDictionaryKeyword").val(res.dataDictionaryKeyword);
                $("#dataDictionaryName").val(res.dataDictionaryName);
                $("#remake").val(res.remake);
            }
            if(show){
                $("#dataDictionaryKeyword").prop("readonly",true);
                $("#dataDictionaryName").prop("readonly",true);
                $("#remake").prop("readonly",true);
                $("#sub").hide();
            }
        }



        //重新渲染表单函数
        function renderForm() {
            layui.use('form', function () {
                var form = layui.form(); //高版本建议把括号去掉，有的低版本，需要加()
                form.render();
            });
        }

        form.render();
    });

</script>
</body>
</html>